package cn.wolfcode.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
@ToString
public class SystemDictionaryItem {
    /**
     * 主键
     */
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 序号
     */
    private Integer sequence;

    /**
     * 所属目录
     */
    private Long type_id;

    /**
     * 上级明细
     */
    private Long parent_id;

    //字典目录对象
    private SystemDictionary systemDictionary;

    //上级明细
    private SystemDictionaryItem parent;

    public String toJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("sequence", sequence);

        if (systemDictionary != null) {
            map.put("typeId", systemDictionary.getId());
        }
        if (parent != null) {
            map.put("parentId", parent.getId());

        }
        return JSON.toJSONString(map);
    }
}